package movieGandalf.dataObjects;

import java.sql.Connection;

import movieGandalf.database.MovieTools;
import movieGandalf.logicGuiConnection.MPAARating;

public class MPAARatingImp implements MPAARating{
	
	private Integer id;
	
	private String mpaaRating;
	
	public MPAARatingImp(Integer id, String mpaaRating){
		this.id = id;
		this.mpaaRating = mpaaRating;
	}
	
	public Integer getID() {
		return this.id;
	}
	
	public String getMPAARating() {
		if (mpaaRating != null)
			return mpaaRating;
		
		if (id == null)
			return null;
		
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		mpaaRating = MovieTools.getMPAARating(conn, this.id);
		
		return mpaaRating;
	}

	public void setID(Integer newID) {
		this.id = newID;
		
	}
	
	public void setMPAARating(String newMPAARating) {
		this.mpaaRating = newMPAARating;
	}
	
	public boolean update() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateMPAARating(conn, this);
	}
	
	public boolean delete() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteObject(conn,this);
	}
}
